<template>
  <div>
    <h1>用户列表</h1>
    <el-table :data="list" stripe style="width: 100%" border>
      <el-table-column prop="id" label="ID" width="253px"> </el-table-column>
      <el-table-column prop="username" label="用户名" width="253px">
      </el-table-column>
      <el-table-column prop="email" label="邮箱" width="253px">
      </el-table-column>
      <el-table-column prop="phone" label="电话" width="253px">
      </el-table-column>
      <el-table-column prop="createTime" label="注册时间" width="253px">
        <template slot-scope="scope">{{
          scope.row.createTime | filtime
        }}</template>
      </el-table-column>
    </el-table>

    <!-- 分页器 -->
    <el-pagination
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="size"
      :current-page="page"
      @current-change="change"
      @size-change="change1"
    >
    </el-pagination>
  </div>
</template>

<script>
import { USERLIST } from "../request/http";
export default {
  data() {
    return {
      list: [],
      size: 5,
      page: 1,
      total:0
    };
  },
  mounted() {
    this.getlist(); //挂载
  },
  methods: {
    async getlist() {
      const { data: res } = await USERLIST(`user/list.do`,{pageSize:this.size,pageNum:this.page});
      console.log(res.data)
      this.list = res.data.list;
      this.total=res.data.total
      // console.log(res.data.list);
    },
    //分页器
    change(val) {
      this.page = val;
       this.getlist();
    },
    change1(a) {
      this.size = a;
       this.getlist();
    },
  },
  // // 计算属性
  // computed: {
  //   reslist() {
  //     return this.list.slice(
  //       this.size * (this.page - 1),
  //       this.size * this.page
  //     );
  //   },
  // },
  // 时间过滤器
  filters: {
    filtime(val) {
      var date = new Date(val);
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var datee = date.getDate();
      var day = date.getDay();
      var time = year + "-" + month + "-" + datee  
      function getTimerr() {
        var time = new Date();
        var hour = time.getHours();
        hour = hour < 10 ? "0" + hour : hour;
        var minute = time.getMinutes();
        minute = minute < 10 ? "0" + minute : minute;
        var second = time.getSeconds();
        second = second < 10 ? "0" + second : second;
        return hour + ":" + minute + ":" + second;
      }
      return time + " " + getTimerr();
    },
    
  },
};
</script>